package cn.iocoder.lw.module.core.dal.mysql.evaluation;

import cn.iocoder.lw.framework.common.pojo.PageResult;
import cn.iocoder.lw.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.lw.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.lw.module.core.dal.dataobject.evaluation.CoreWorkOrderEvaluationDO;
import cn.iocoder.lw.module.core.controller.admin.evaluation.vo.evaluation.CoreWorkOrderEvaluationPageReqVO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 工单评价 Mapper
 *
 * @author Lw源码
 */
@Mapper
public interface CoreWorkOrderEvaluationMapper extends BaseMapperX<CoreWorkOrderEvaluationDO> {

    default PageResult<CoreWorkOrderEvaluationDO> selectPage(CoreWorkOrderEvaluationPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<CoreWorkOrderEvaluationDO>()
                .eqIfPresent(CoreWorkOrderEvaluationDO::getWorkOrderId, reqVO.getWorkOrderId())
                .eqIfPresent(CoreWorkOrderEvaluationDO::getInitiatorId, reqVO.getInitiatorId())
                .eqIfPresent(CoreWorkOrderEvaluationDO::getAssigneeId, reqVO.getAssigneeId())
                .eqIfPresent(CoreWorkOrderEvaluationDO::getEvaluationLevel, reqVO.getEvaluationLevel())
                .eqIfPresent(CoreWorkOrderEvaluationDO::getRead, reqVO.getRead())
                .betweenIfPresent(CoreWorkOrderEvaluationDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(CoreWorkOrderEvaluationDO::getCreateTime));
    }

    default CoreWorkOrderEvaluationDO selectByWorkOrderId(Long workOrderId) {
        return selectOne(new LambdaQueryWrapperX<CoreWorkOrderEvaluationDO>()
                .eq(CoreWorkOrderEvaluationDO::getWorkOrderId, workOrderId)
                .orderByDesc(CoreWorkOrderEvaluationDO::getCreateTime)
                .last("LIMIT 1"));
    }

    default List<CoreWorkOrderEvaluationDO> selectListByInitiatorId(Long initiatorId) {
        return selectList(new LambdaQueryWrapperX<CoreWorkOrderEvaluationDO>()
                .eq(CoreWorkOrderEvaluationDO::getInitiatorId, initiatorId)
                .orderByDesc(CoreWorkOrderEvaluationDO::getCreateTime));
    }

    default List<CoreWorkOrderEvaluationDO> selectListByAssigneeId(Long assigneeId) {
        return selectList(new LambdaQueryWrapperX<CoreWorkOrderEvaluationDO>()
                .eq(CoreWorkOrderEvaluationDO::getAssigneeId, assigneeId)
                .orderByDesc(CoreWorkOrderEvaluationDO::getCreateTime));
    }

    default List<CoreWorkOrderEvaluationDO> selectUnreadEvaluations() {
        return selectList(new LambdaQueryWrapperX<CoreWorkOrderEvaluationDO>()
                .eq(CoreWorkOrderEvaluationDO::getRead, false)
                .orderByDesc(CoreWorkOrderEvaluationDO::getCreateTime));
    }

    default List<CoreWorkOrderEvaluationDO> selectUnreadEvaluationsByAssigneeId(Long assigneeId) {
        return selectList(new LambdaQueryWrapperX<CoreWorkOrderEvaluationDO>()
                .eq(CoreWorkOrderEvaluationDO::getAssigneeId, assigneeId)
                .eq(CoreWorkOrderEvaluationDO::getRead, false)
                .orderByDesc(CoreWorkOrderEvaluationDO::getCreateTime));
    }

}